fix: use regex exact match in get_current_app to prevent package substring misidentification#415
Open
nankingjing wants to merge 1 commit into
Open
Conversation
…tring misidentification
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
phone_agent/adb/device.pyget_current_app()uses substring matching (if package in line) to identify the running app fromdumpsys windowoutput. This causes misidentification when one package name is a substring of another.Concrete example
The
APP_PACKAGESdict contains:"GoogleDrive": "com.google.android.apps.docs"(Google Drive)"Google Docs": "com.google.android.apps.docs.editors.docs"(Google Docs)"GoogleSlides": "com.google.android.apps.docs.editors.slides"(Google Slides)When Google Docs is running,
dumpsys windowoutputs:The substring check
"com.google.android.apps.docs" in lineevaluates toTrue, so it incorrectly returns "Google Drive" (which appears first in dict insertion order) instead of "Google Docs". The same misidentification occurs with Google Slides.Fix
Replace substring matching with regex-based exact package extraction followed by exact dict lookup. The regex
r"\s(\w+)\s+([\w.]+)/"extracts the package portion from the dumpsys window format (Window{... u0 com.example.app/...}).A substring-matching fallback is kept for unusual dumpsys formats where the regex may not match.
Verification
python -m py_compilepasses on the changed filedumpsys windowlines — correctly extractscom.google.android.apps.docs.editors.docsfor Docs vscom.google.android.apps.docsfor Drive